//
//  MagicRay.m
//  TowerDefence
//
//  Created by k3 on 6/6/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "MagicRay.h"

@implementation MagicRay

-(id)initMagicRayWith:(GameLayer *)_gameLayer tower:(GameObject *)_tower {
    self = [super initBulletObjectWith:_gameLayer tower:_tower];
    velocity = 0.5f;
    damage = 25;
    [self loadBulletComponent];
    return self;
}

-(void)loadBulletComponent {
//    NSMutableArray *animArray = [self loadAnimationWithNumberOfFrames:11 withFrameName:@"magic_ray"];
//    CCAnimation *animation = [CCAnimation animationWithFrames:animArray delay:0.125];
//    [spriteBody runAction:[CCAnimate actionWithAnimation:animation]];
    spriteBody = [[CCSprite alloc]initWithSpriteFrameName:@"magic_ray0.png"];
}

-(void)fireTarget:(CGPoint)_targetPoint {
    targetPoint = _targetPoint;
    [self moveToTarget];
}

-(void)moveToTarget {
    CCAnimation *explosiveAnimation = [self loadAnimationFromCacheByName:@"magic_ray" withCount:11 delay:0.05f];;
    
    CCCallFunc *firedCallback = [CCCallFunc actionWithTarget:self selector:@selector(hitTargetCallback)];
    
    spriteBody.scale = 0;
    [spriteBody runAction:[CCScaleTo actionWithDuration:velocity scale:1]];
    [spriteBody runAction:[CCSequence actions:[CCMoveTo actionWithDuration:velocity position:targetPoint], [CCAnimate actionWithAnimation:explosiveAnimation restoreOriginalFrame:NO], firedCallback, nil]];
}

-(void)hitTargetCallback {
    [super hitTargetCallback];
}

-(void)dealloc {
    [super dealloc];
}

@end
